# -*- coding: utf-8 -*-
from datetime import timedelta
from jms.dwd.January.dwd_order_detail_dt import jms_dwd__dwd_order_detail_dt
from utils.operators.spark_sql_operator import SparkSqlOperator

jms_dws__dws_order_hour_cnt_dt = SparkSqlOperator(
    task_id='jms_dws__dws_order_hour_cnt_dt',
    task_concurrency=1,
    pool_slots=1,
    execution_timeout=timedelta(hours=1),
    email=['chenhongping@yl-scm.com','yl_bigdata@yl-scm.com'],
    master='yarn',
    name='jms_dws__dws_order_hour_cnt_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dws/January/dws_order_cnt_dt/hour.hql',
    driver_memory='3G' , 
    driver_cores=2 , 
    executor_cores=2 , 
    executor_memory='1G' , 
    num_executors=2 , 
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 2 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '2G' , 
          'spark.sql.shuffle.partitions': 600,
          'spark.default.paralleism': 600,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.network.timeout': 300,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 12,  # 每天生成 35 个分区
              'hive.exec.max.dynamic.partitions.pernode': 12,  # 每天生成 35 个分区
              },
)


jms_dws__dws_order_day_cnt_dt = SparkSqlOperator(
    task_id='jms_dws__dws_order_day_cnt_dt',
    task_concurrency=1,
    pool_slots=1,
    execution_timeout=timedelta(hours=1),
    email='chenhongping@yl-scm.com',
    master='yarn',
    name='jms_dws__dws_order_day_cnt_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dws/January/dws_order_cnt_dt/day.hql',
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.sql.shuffle.partitions': 600,
          'spark.default.paralleism': 600,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.network.timeout': 300,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 12,  # 每天生成 35 个分区
              'hive.exec.max.dynamic.partitions.pernode': 12,  # 每天生成 35 个分区
              },
)

jms_dws__dws_order_day_cnt_dt << jms_dws__dws_order_hour_cnt_dt \
<< [jms_dwd__dwd_order_detail_dt,
]
